package CH01数组结构.LeetCode双指针;

public class LC680 {
    public boolean validPalindrome(String s) {
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            } else {
                return check(s,left + 1,right) || check(s, left, right - 1);
            }
        }
        return true;
    }

    private boolean check(String s, int left, int right) {
        for (int i = left, j = right; i < j;i++,j--) {
            if (s.charAt(i) != s.charAt(j)) {
                return false;
            }
        }
        return true;
    }
}